// 邮件模块 - 统一入口文件
// 负责协调各个子模块

const EmailModule = {
    // 共享缓存数据
    cache: {
        accounts: [],
        currentAccount: null,
        currentFolder: null,
        currentEmail: null
    },
    
    isLoading: false,

    // 初始化邮件模块
    init: function() {
        // 初始化各个子模块
        EmailDetailsManager.init();
        EmailListManager.init();
        EmailOperationsManager.init();
        EmailInteractionsManager.initSwipeDelete();
        EmailInteractionsManager.initContextMenu();
    },

    // ========== 以下是保持向后兼容的代理方法 ==========

    // 加载邮件列表 - 代理到 EmailListManager
    loadEmailList: function(folder, accountId, append = false, targetElement, isSync = false) {
        return EmailListManager.loadEmailList(folder, accountId, append, targetElement, isSync);
    },

    // 创建邮件项DOM元素 - 代理到 EmailListManager
    createEmailItemElement: function(email) {
        return EmailListManager.createEmailItemElement(email);
    },

    // 查看邮件 - 代理到 EmailDetailsManager
    viewEmail: function(accountId, emailId, element) {
        return EmailDetailsManager.viewEmail(accountId, emailId, element);
    },

    // 打开撰写邮件弹窗 - 代理到 EmailDraftManager
    openComposeModal: function(options) {
        return EmailDraftManager.openComposeModal(options);
    },

    // 删除邮件 - 代理到 EmailOperationsManager
    deleteEmail: function(accountId, emailId) {
        return EmailOperationsManager.deleteEmail(accountId, emailId);
    },

    // 彻底删除邮件 - 代理到 EmailOperationsManager
    permanentDeleteEmail: function(accountId, emailId) {
        return EmailOperationsManager.permanentDeleteEmail(accountId, emailId);
    },

    // 批量彻底删除 - 代理到 EmailOperationsManager
    permanentDeleteSelectedEmails: function() {
        return EmailOperationsManager.permanentDeleteSelectedEmails();
    },

    // 移动邮件 - 代理到 EmailOperationsManager
    moveEmail: function(accountId, emailId, currentFolder) {
        return EmailOperationsManager.moveEmail(accountId, emailId, currentFolder);
    },

    // 回复邮件 - 代理到 EmailDetailsManager
    replyEmail: function() {
        return EmailDetailsManager.replyEmail();
    },

    // 转发邮件 - 代理到 EmailDetailsManager
    forwardEmail: function() {
        return EmailDetailsManager.forwardEmail();
    },

    // 标记为未读 - 代理到 EmailOperationsManager
    markAsUnread: function(accountId, emailId) {
        return EmailOperationsManager.markAsUnread(accountId, emailId);
    }
};
